package com.winit.openapi.tms.controller;

import javax.annotation.Resource;

import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import com.alibaba.fastjson.JSONObject;
import com.winit.oms.spi.outbound.OutboundSystemOrderTMSCostTestService;
import com.winit.oms.spi.outbound.command.order.QueryOrderCostCommand;
import com.winit.openapi.constants.ErrorCode;
import com.winit.openapi.controller.BaseController;
import com.winit.openapi.exception.ApiException;
import com.winit.openapi.model.RequestMsg;
import com.winit.openapi.model.ResponseMsg;

/**
 * TMS成本测试接口
 * 
 * @version <pre>
 * Author	Version		Date		Changes
 * bing.gu 	1.0  		2016年12月22日 	Created
 *
 * </pre>
 * @since 1.
 */
@Controller
@RequestMapping(value = "/tms/cost")
public class CostTestController extends BaseController {

    @Resource
    private OutboundSystemOrderTMSCostTestService outboundSystemOrderTMSCostTestService;

    /**
     * 海外仓出库单TMS成本测试
     * 
     * @param requestMsg
     * @param responseMsg
     * @return
     */
    @RequestMapping(value = "/test")
    public String costTest(@ModelAttribute RequestMsg requestMsg, @ModelAttribute ResponseMsg responseMsg) {

        Object obj = requestMsg.getData();
        if (obj instanceof JSONObject) {
            JSONObject json = (JSONObject) obj;
            String orderNo = json.getString("orderNo");
            if (StringUtils.isBlank(orderNo)) {
                throw new ApiException("Order No can't be null");
            }
            QueryOrderCostCommand command = new QueryOrderCostCommand();
            command.setOrderNo(orderNo);
            outboundSystemOrderTMSCostTestService.costTest(command);
        } else {
            throw new ApiException(ErrorCode.FIELD_TYPE_ERROR, "data");
        }
        return SUCCESS;
    }
}
